package com.ruoyi.ss.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.ss.domain.ActivityGroup;
import com.ruoyi.ss.service.IActivityGroupService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 活动组Controller
 * 
 * @author ruoyi
 * @date 2025-08-04
 */
@RestController
@RequestMapping("/ss/group")
public class ActivityGroupController extends BaseController
{
    @Autowired
    private IActivityGroupService activityGroupService;

    /**
     * 查询活动组列表
     */
    @PreAuthorize("@ss.hasPermi('ss:group:list')")
    @GetMapping("/list")
    public TableDataInfo list(ActivityGroup activityGroup)
    {
        startPage();
        List<ActivityGroup> list = activityGroupService.selectActivityGroupList(activityGroup);
        return getDataTable(list);
    }

    /**
     * 导出活动组列表
     */
    @PreAuthorize("@ss.hasPermi('ss:group:export')")
    @Log(title = "活动组", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ActivityGroup activityGroup)
    {
        List<ActivityGroup> list = activityGroupService.selectActivityGroupList(activityGroup);
        ExcelUtil<ActivityGroup> util = new ExcelUtil<ActivityGroup>(ActivityGroup.class);
        util.exportExcel(response, list, "活动组数据");
    }

    /**
     * 获取活动组详细信息
     */
    @PreAuthorize("@ss.hasPermi('ss:group:query')")
    @GetMapping(value = "/{activityGroupId}")
    public AjaxResult getInfo(@PathVariable("activityGroupId") Long activityGroupId)
    {
        return success(activityGroupService.selectActivityGroupByActivityGroupId(activityGroupId));
    }

    /**
     * 新增活动组
     */
    @PreAuthorize("@ss.hasPermi('ss:group:add')")
    @Log(title = "活动组", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ActivityGroup activityGroup)
    {
        return toAjax(activityGroupService.insertActivityGroup(activityGroup));
    }

    /**
     * 修改活动组
     */
    @PreAuthorize("@ss.hasPermi('ss:group:edit')")
    @Log(title = "活动组", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ActivityGroup activityGroup)
    {
        return toAjax(activityGroupService.updateActivityGroup(activityGroup));
    }

    /**
     * 删除活动组
     */
    @PreAuthorize("@ss.hasPermi('ss:group:remove')")
    @Log(title = "活动组", businessType = BusinessType.DELETE)
	@DeleteMapping("/{activityGroupIds}")
    public AjaxResult remove(@PathVariable Long[] activityGroupIds)
    {
        return toAjax(activityGroupService.deleteActivityGroupByActivityGroupIds(activityGroupIds));
    }
}
